import { defineStore } from 'pinia';
//定义选项卡数据类型
export type Tab = {
    title: string,
    path: string,

}
//定义选项卡类型
export type TabState = {
    tabList: Tab[],
}
export const tabStore = defineStore('tabStore', {
    state: (): TabState => {
        return { tabList: [] }
    }
    ,
    getters: {
        getTab(state) {
            return state.tabList
        }
    },
    actions: {
        addTab(tab: Tab) {
            //判断是否存在数据
            if (this.tabList.some(item => item.path === tab.path)) return;
            if (tab.path == '/dashboard') {
                this.tabList.unshift(tab)
            } else {
                this.tabList.push(tab)
            }

        }
    },
    persist: {
        enabled: true,
        strategies: [
            { paths: ['tabList'], storage: localStorage }
        ]
    }

})